let menu1 = document.querySelector("#menu1 .dropdown-content")
let menu2 = document.querySelector("#menu2 .dropdown-content")
let container_uu = document.querySelector("#container #uu")
//导航栏部分
fetch("http://chst.vip:1234/api/getgsshop")
    .then(body => body.json())
    .then(res => {
        console.log(res);
        let el = ""
        res.result.forEach(item => {
            el += `<a href="#" shopId=${item.shopId}>${item.shopName}</a>`
        })
        menu1.innerHTML = el
    })

fetch("http://chst.vip:1234/api/getgsshoparea")
    .then(body => body.json())
    .then(res => {
        console.log(res);
        let el = ""
        res.result.forEach(item => {
            el += `<a href="#" areaId=${item.areaId}>${item.areaName}</a>`
        })
        menu2.innerHTML = el
    })

let id1 = 0
let id2 = 0
$("#menu1 .dropdown-content").on("click", "a", function () {
    id1 = this.getAttribute('shopId');
    fetch("http://chst.vip:1234/api/getgsproduct?shopid=" + id1 + "&areaid=" + id2)
        .then(body => body.json())
        .then(res => {
            console.log(res);
            let el = ""
            res.result.forEach(item => {
                el += `
                <li>
                    <img src="${item.productImg}">
                    <div class="word">
                        <span class="name">${item.productName}</span>
                        <p class="price">${item.productPrice}</p>
                    </div>  
                </li>`
            })
            container_uu.innerHTML = el
        })
})

$("#menu2 .dropdown-content").on("click", "a", function () {
    id2 = this.getAttribute('areaId');
    fetch("http://chst.vip:1234/api/getgsproduct?shopid=" + id1 + "&areaid=" + id2)
        .then(body => body.json())
        .then(res => {
            console.log(res);
            let el = "";
            res.result.forEach(item => {
                el += `
                <li>
                    <img src="${item.productImg}">
                    <div class="word">
                        <span class="name">${item.productName}</span>
                        <p class="price">${item.productPrice}</p>
                    </div>  
                </li>
                `
            })
            container_uu.innerHTML = el;
        })
})


fetch("http://chst.vip:1234/api/getgsproduct?shopid=" + id1 + "&areaid=" + id2)
    .then(body => body.json())
    .then(res => {
        console.log(res);
        let el = "";
        res.result.forEach(item => {
            el += `
            <li>
            <img src="${item.productImg}">
            <div class="word">
                <span class="name">${item.productName}</span>
                <p class="price">${item.productPrice}</p>
            </div>  
        </li>`
        })
        container_uu.innerHTML = el;
    })
